<template>
  <div class="product" :class="className">
    <template v-if="list && list.length > 0">
        <el-row>
        <el-col
          :span="8"
          v-for="(item, index) in list" :key="index"
          :offset="index > 0 ? 2 : 0"
        >
          <el-card :body-style="{ padding: '0px' }">
            <img :src="item.url" class="image">
            <div style="padding: 14px">
              <span>卡片{{item.title}}</span>
              <div class="bottom clearfix">
                <p>{{item.link}}</p>
                <!-- <time class="time">{{ item.link }}</time> -->
                <!-- <el-button type="text" class="button">操作按钮</el-button> -->
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </template>
    <template v-else>
      <el-row>
        <el-col
          :span="8"
          v-for="(o, index) in 2"
          :key="o"
          :offset="index > 0 ? 2 : 0"
        >
          <el-card :body-style="{ padding: '0px' }">
            <img
              src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"
              class="image"
            />
            <div style="padding: 14px">
              <span>好吃的汉堡</span>
              <div class="bottom clearfix">
                <!-- <time class="time">{{ currentDate }}</time> -->
                <el-button type="text" class="button">操作按钮</el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </template>
  </div>
</template>

<script>
export default {
  name: "Product",
  props: ["data", "className"],
  data(){
    return {
      list:[]
    }
  },
  computed: {
    options() {
      return this.data.options;
    },
    line() {
      return this.options.volumeStr && this.options.goodRatio ? "| " : "";
    },
    
  },
  watch:{
    data:{
      handler(val) {
        // console.log(val,'val');
        // this.token = val
        this.list = val.data
        // if (val.templateContent.cards) {
        //   this.cards = val.templateContent.cards;
        // }
      },
      deep: true, // 深度监听
      immediate: true, // 初次监听即执行
    }
  }
};
</script>

<style lang="scss" scoped>
.product {
  display: flex;
  flex-wrap: wrap;
  padding: 4px 8px;
  box-sizing: border-box;
  * {
    box-sizing: border-box;
  }
  &.one .product-item {
    width: 100%;
    padding: 10px;
    display: flex;
    border-bottom: 1px dashed #eee;
    .image {
      width: 100px;
      border-radius: 5px;
      overflow: hidden;
      margin-right: 10px;
    }
    .info {
      padding: 0 5px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;
      .price {
        font-size: 20px;
        margin: 0;
      }
      .num {
        margin: 12px 0 0;
      }
    }
  }
  &.three .product-item {
    // width: 33.33%;
    .info .price {
      font-size: 16px;
    }
    &.product-default:nth-of-type(3) {
      display: block;
    }
  }
  .product-item {
    width: 50%;
    padding: 5px;
    &.product-default:nth-of-type(3) {
      display: none;
    }
    .image {
      font-size: 0;
      img {
        max-width: 100%;
      }
    }
    .info {
      padding: 10px 5px 0;
      .name {
        font-size: 14px;
        margin: 0;
        color: #333;
        text-overflow: ellipsis;
        word-break: break-all;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        height: 38px;
        line-height: 18px;
      }
      .num {
        font-size: 12px;
        color: #d23000;
        font-weight: 600;
      }
      .price {
        font-weight: 600;
        margin: 12px 0 0;
        font-size: 18px;
        span:nth-of-type(1) {
          color: red;
        }
        span:nth-of-type(2) {
          color: #b5b5b5;
          font-weight: 400;
          font-size: 12px;
          margin-left: 4px;
          text-decoration: line-through;
        }
      }
    }
  }
  .time {
    font-size: 13px;
    color: #999;
  }
  
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }
}
</style>